package info.liujiachen.security.test.handler;

import info.liujiachen.security.test.config.JwtConfig;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class JwtAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication auth) {
        response.addHeader(JwtConfig.HEADER_TOKEN_KEY, JwtConfig.HEADER_TOKEN_VALUE_PREFIX + auth.getPrincipal());
    }

}
